﻿@{
    var isCheckChkCode = (ViewBag.IsCheckChkCode as bool?) ?? true;
}
<script type="text/javascript">
    if (window.top != window) {
        top.location.href = location.href;
    }
</script>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>药房药库系统</title>
    <link rel="shortcut icon" href="@SiteUrl.GetStaticResourceScriptUrl("~/img/newtouchcloud.ico")">
    <link href="@SiteUrl.GetStaticResourceScriptUrl("~/Content/css/login.css", false)" rel="stylesheet" />
    <script src="@SiteUrl.GetStaticResourceScriptUrl("~/js/jquery/jquery.choose.js")"></script>
    <script src="@SiteUrl.GetStaticResourceScriptUrl("~/js/cookie/jquery.cookie.js")"></script>
    <script src="@SiteUrl.GetStaticResourceScriptUrl("~/js/md5/jquery.md5.js")"></script>
    <style>

    </style>
</head>
<body style="overflow: hidden;">
    <form id="form1" style="overflow: hidden;">
        <div class="login">
            <div class="login-head">
                <div class="login-head-a">
                    <img src="~/Content/img/NewTouch1.png" title="" alt="" />
                </div>
            </div>
            <div class="login-con">
                <div class="login-a">
                    <div class="login-b">
                        <div class="login-b-a">
                            <a class="lo_mod tab_on">欢迎登录</a>
                        </div>
                        <div class="login-b-b">
                            <ul>
                                <li>
                                    <label for="userName" class="ui-label">
                                        <span class="ui-icon ui-icon-userDEF">
                                        </span>
                                    </label>
                                    <input id="txt_account" value="" type="text" placeholder="登录账号">
                                </li>
                                <li>
                                    <label for="userName" class="ui-label"><span class="ui-icon-ysh ui-icon-userDEF"></span></label>
                                    <input id="txt_password" value="" type="password" placeholder="登录密码">
                                </li>
                                @{
                                    if (isCheckChkCode)
                                    {
                                        <li>
                                            <input id="txt_code" type="text" placeholder="验证码" style="width: 130px; float: left;">
                                            <div style="width: 120px; float: left; padding-top: -15px; padding-left: 14px;">
                                                <img id="imgcode" class="authcode" src="~/Login/GetAuthCode" width="50" height="25" />
                                                <a id="switchCode" href="javascript:void();" style="text-decoration: none;">换一张</a>
                                            </div>
                                        </li>
                                    }
                                }
                                <li class="login-x">
                                    <div class="login-x-a">
                                        <button id="login_button" type="button" style="background-color: #3b9df0; color: white">
                                            <span>登录</span>
                                        </button>
                                    </div>
                                </li>
                            </ul>
                            <div class="login_tips"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="login-foot">
            </div>
        </div>
        <script type="text/javascript">
        (function($) {
            $.login = {
                formMessage: function(msg) {
                    $('.login_tips').find('.tips_msg').remove();
                    $('.login_tips').append('<div class="tips_msg"><i class="fa fa-question-circle"></i>' +
                        msg +
                        '</div>');
                },
                loginClick: function() {
                    var $username = $("#txt_account");
                    var $password = $("#txt_password");
                    var $code = $("#txt_code");
                    if ($username.val() == "") {
                        $username.focus();
                        $.login.formMessage('请输入用户名/手机号/邮箱。');
                        return false;
                    } else if ($password.val() == "") {
                        $password.focus();
                        $.login.formMessage('请输入登录密码。');
                        return false;
                    } else if ($code.val() == "") {
                        $code.focus();
                        $.login.formMessage('请输入验证码。');
                        return false;
                    } else {
                        $("#login_button").attr('disabled', 'disabled').find('span').html("loading...");
                        $.ajax({
                            url: "/Login/CheckLogin",
                            data: { username: $username.val(), password: $.md5($password.val()), code: $code.val() },
                            type: "post",
                            dataType: "json",
                            success: function(data) {
                                if (data.state == "success") {
                                    $("#login_button").find('span').html("登录成功，正在跳转...");
                                    window.setTimeout(function() {
                                            window.location.href = "/Home/Index";
                                        },
                                        10);
                                } else {
                                    $("#login_button").removeAttr('disabled').find('span').html("登录");
                                    $("#switchCode").trigger("click");
                                    $code.val('');
                                    $.login.formMessage(data.message);
                                }
                            }
                        });
                    }
                },
                init: function() {
                    $('.wrapper').height($(window).height());
                    $(".container").css("margin-top", ($(window).height() - $(".container").height()) / 2 - 50);
                    $(window).resize(function(e) {
                        $('.wrapper').height($(window).height());
                        $(".container").css("margin-top", ($(window).height() - $(".container").height()) / 2 - 50);
                    });
                    $("#switchCode").click(function() {
                        $("#imgcode").attr("src", "/Login/GetAuthCode?time=" + Math.random());
                    });
                    var loginErrorKey = "Newtouch_login_error";
                    var appId = '@(Newtouch.Infrastructure.Constants.AppId)';
                    if (appId) {
                        loginErrorKey = appId + "_" + loginErrorKey;
                    }
                    var login_error = top.$.cookie(loginErrorKey);
                    if (login_error != null) {
                        switch (login_error) {
                        case "overdue":
                            $.login.formMessage("系统登录已超时,请重新登录");
                            break;
                        case "sidelined":
                            $.login.formMessage("该账号已在其他地方登录，您已被迫下线");
                            break;
                        case "-1":
                            $.login.formMessage("系统未知错误,请重新登录");
                            break;
                        }
                        top.$.cookie(loginErrorKey, '', { path: "/", expires: -1 });
                        document.cookie = appId + '_newtouch_loginuserkey_2016' + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; domain=' + location.hostname;
                    }
                    $("#login_button").click(function() {
                        $.login.loginClick();
                    });
                    document.onkeydown = function(e) {
                        if (!e) e = window.event;
                        if ((e.keyCode || e.which) == 13) {
                            document.getElementById("login_button").focus();
                            document.getElementById("login_button").click();
                        }
                    }
                }
            };
            $(function() {
                $.login.init();
            });
        })(jQuery);
        </script>
    </form>
</body>
</html>
